<?php
//include("../include/function.php");
dbconnect();
session_start();
?>

<script src="http://localhost/php/login/js/jquery.js">
</script>
<script>
$(document).ready(function(){
  $(".firstname").keyup(function(){
   var firstname = $(".firstname").val();
    $.ajax({url:"autocomplete.php?value=" +firstname,
	
	
	success:function(result){
	//alert('sss');
	  $(".option").show();
      $(".option").html(result);
		  $(".option").each(function(){
			  $(".option ul li").click(function(){
				  var textvalue = $(this).html();
				  $(".firstname").val(textvalue);
				  $(".option").hide();
			  //alert($(this).attr('id'));
				  var roleid = $(this).attr('id');
				  $(".roleid").val(roleid);
			  });
		  });
    },
	
	
	error:function(result){
      $(".option").html(result);
    }
	
	
	
	});
  });
});
</script>


<?php
if($_SESSION["loggedin"]==true && $_SESSION["role"]==admin)
{
if(isset($_SESSION[msg]))
{
echo $_SESSION[msg];
unset($_SESSION[msg]);
}
?>
<?php
$id = $_GET['id'];

$edit = "SELECT * from adminform WHERE adminid='$id'";
$editresult = mysql_query($edit);
$editvalue = mysql_fetch_array($editresult);

$edit1= "SELECT * from userrole";
$editresult1 = mysql_query($edit1);
$editvalue1 = mysql_fetch_array($editresult1);
//print_r($editvalue1);


$edit2= "SELECT * from role_management WHERE roleid='$editvalue1[roleid]'";
//print_r($edit2);
$editresult2 = mysql_query($edit2);
$editvalue2 = mysql_fetch_array($editresult2);
//print_r($editvalue2 );
?>
<form action="index.php?management=user&&task=edit&&id=<?php echo $adminform['adminid']; ?>" method="post">
<input type="hidden" value="<?php echo "$editvalue[adminid]";?> " name="id" />

<label>Employee Name</label>
<input type="text" value="<?php echo "$editvalue[addempname]";?>" name="addempname" /><br><br>
<label>Father Name</label>
<input type="text" value="<?php echo "$editvalue[addfathername]";?>" name="addfathername" /><br><br>
<label>Mother Name</label>
<input type="text" value="<?php echo "$editvalue[addmothername]";?>" name="addmothername" /><br><br>
<label>Address</label>
<textarea type="text" value="" name="addaddress" ><?php echo "$editvalue[addaddress]";?></textarea><br><br>
<label>PAN card No</label>
<input type="text" value="<?php echo "$editvalue[addpanno]";?>" name="addpanno" /><br><br>
<label>Email id</label>
<input type="text" value="<?php echo "$editvalue[addemailid]";?>" name="addemailid" /><br><br>
<label>Mobile/Telephone</label>
<input type="text" value="<?php echo "$editvalue[addmobile]";?>" name="addmobile" /><br><br>

<label>Login Username</label>
<input type="text" value="<?php echo "$editvalue[addusername]";?>" name="addusername" /><br><br>
<label>Login Password</label>
<input type="text" value="<?php echo "$editvalue[addpassword]";?>" name="addpassword" /><br><br>

<label>Role</label>
<input type="text" class="firstname"  name="addrole1" value="<?php echo "$editvalue2[rolename]";?>"/>

<input type="text" class="roleid" name="addrole" style="display:none;" value=""/>

<div class="option" style="display:none;  border: 1px solid;
    height: 39px;
    left: 32px;
    margin-right: 103px;
    overflow-x: auto;
    overflow-y: scroll;
    position: relative;
    width: 143px;"></div>
<input type="submit" value="Edit" name="editform" />
</form>
<?php
if(isset($_POST['editform']))
{
$id = $_POST['id'];
//print_r($id);
$updatevalue = array();

$updatevalue[addempname]=$addempname;
$updatevalue[addfathername]=$addfathername;
$updatevalue[addmothername]=$addmothername;
$updatevalue[addaddress]= $addaddress;
$updatevalue[addpanno]=$addpanno;
$updatevalue[addemailid]=$addemailid;
$updatevalue[addmobile]=$addmobile;
$updatevalue[addusername]=$addusername;
$updatevalue[addpassword]=$addpassword;

updatequery("adminform",$updatevalue,"adminid",$id);

/* $update = "UPDATE adminform SET addempname='$addempname',addfathername='$addfathername',addmothername='$addmothername',addaddress='$addaddress',addpanno='$addpanno',addemailid='$addemailid',addmobile='$addmobile',addusername='$addusername',addpassword='$addpassword' WHERE adminid='$id'";
$updatevalue = mysql_query($update); */

$updaterole = "UPDATE userrole SET roleid='$addrole'";
$uq = mysql_query($updaterole);
//print_r($uq);
header("Location: index.php?management=user");
}
}
else
{
header("Location: login.php");
}
?>

